home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / BaseClasses / strmctl.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  6.3 KB  |  159 lines

  1. //------------------------------------------------------------------------------
  2. // File: StrmCtl.h
  3. //
  4. // Desc: DirectShow base classes.
  5. //
  6. // Copyright (c) 1996-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9.  
  10. #ifndef __strmctl_h__
  11. #define __strmctl_h__
  12.  
  13. class CBaseStreamControl : public IAMStreamControl
  14. {
  15. public:
  16.     // Used by the implementation
  17.     enum StreamControlState
  18.     { STREAM_FLOWING = 0x1000,
  19.       STREAM_DISCARDING
  20.     };
  21.  
  22. private:
  23.     enum StreamControlState m_StreamState;      // Current stream state
  24.     enum StreamControlState m_StreamStateOnStop;    // State after next stop
  25.                         // (i.e.Blocking or Discarding)
  26.  
  27.     REFERENCE_TIME  m_tStartTime;       // MAX_TIME implies none
  28.     REFERENCE_TIME  m_tStopTime;        // MAX_TIME implies none
  29.     DWORD           m_dwStartCookie;    // Cookie for notification to app
  30.     DWORD           m_dwStopCookie;     // Cookie for notification to app
  31.     volatile BOOL   m_bIsFlushing;      // No optimization pls!
  32.     volatile BOOL   m_bStopSendExtra;   // bSendExtra was set
  33.     volatile BOOL   m_bStopExtraSent;   // the extra one was sent
  34.  
  35.     CCritSec        m_CritSec;          // CritSec to guard above attributes
  36.  
  37.     // Event to fire when we can come
  38.     // out of blocking, or to come out of waiting
  39.     // to discard if we change our minds.
  40.     //
  41.     CAMEvent            m_StreamEvent;
  42.  
  43.     // All of these methods execute immediately.  Helpers for others.
  44.     //
  45.     void ExecuteStop();
  46.     void ExecuteStart();
  47.     void CancelStop();
  48.     void CancelStart();
  49.  
  50.     // Some things we need to be told by our owning filter
  51.     // Your pin must also expose IAMStreamControl when QI'd for it!
  52.     //
  53.     IReferenceClock *   m_pRefClock;        // Need it to set advises
  54.                         // Filter must tell us via
  55.                         // SetSyncSource
  56.     IMediaEventSink *   m_pSink;            // Event sink
  57.                         // Filter must tell us after it
  58.                         // creates it in JoinFilterGraph()
  59.     FILTER_STATE    m_FilterState;          // Just need it!
  60.                         // Filter must tell us via
  61.                         // NotifyFilterState
  62.     REFERENCE_TIME  m_tRunStart;            // Per the Run call to the filter
  63.  
  64.     // This guy will return one of the three StreamControlState's.  Here's what
  65.     // the caller should do for each one:
  66.     //
  67.     // STREAM_FLOWING:      Proceed as usual (render or pass the sample on)
  68.     // STREAM_DISCARDING:   Calculate the time 'til *pSampleStop and wait
  69.     //              that long for the event handle
  70.     //              (GetStreamEventHandle()).  If the wait
  71.     //              expires, throw the sample away.  If the event
  72.     //              fires, call me back - I've changed my mind.
  73.     //
  74.     enum StreamControlState CheckSampleTimes( const REFERENCE_TIME * pSampleStart,
  75.                           const REFERENCE_TIME * pSampleStop );
  76.  
  77. public:
  78.     // You don't have to tell us much when we're created, but there are other
  79.     // obligations that must be met.  See SetSyncSource & NotifyFilterState
  80.     // below.
  81.     //
  82.     CBaseStreamControl();
  83.     ~CBaseStreamControl();
  84.  
  85.     // If you want this class to work properly, there are thing you need to
  86.     // (keep) telling it.  Filters with pins that use this class
  87.     // should ensure that they pass through to this method any calls they
  88.     // receive on their SetSyncSource.
  89.  
  90.     // We need a clock to see what time it is.  This is for the
  91.     // "discard in a timely fashion" logic.  If we discard everything as
  92.     // quick as possible, a whole 60 minute file could get discarded in the
  93.     // first 10 seconds, and if somebody wants to turn streaming on at 30 
  94.     // minutes into the file, and they make the call more than a few seconds
  95.     // after the graph is run, it may be too late!
  96.     // So we hold every sample until it's time has gone, then we discard it.
  97.     // The filter should call this when it gets a SetSyncSource
  98.     //
  99.     void SetSyncSource( IReferenceClock * pRefClock )
  100.     {
  101.         CAutoLock lck(&m_CritSec);
  102.         if (m_pRefClock) m_pRefClock->Release();
  103.             m_pRefClock = pRefClock;
  104.         if (m_pRefClock) 
  105.             m_pRefClock->AddRef();
  106.     }
  107.  
  108.     // Set event sink for notifications
  109.     // The filter should call this in its JoinFilterGraph after it creates the
  110.     // IMediaEventSink
  111.     //
  112.     void SetFilterGraph( IMediaEventSink *pSink ) {
  113.         m_pSink = pSink;
  114.     }
  115.  
  116.     // Since we schedule in stream time, we need the tStart and must track the
  117.     // state of our owning filter.
  118.     // The app should call this ever state change
  119.     //
  120.     void NotifyFilterState( FILTER_STATE new_state, REFERENCE_TIME tStart = 0 );
  121.  
  122.     // Filter should call Flushing(TRUE) in BeginFlush,
  123.     // and Flushing(FALSE) in EndFlush.
  124.     //
  125.     void Flushing( BOOL bInProgress );
  126.  
  127.  
  128.     // The two main methods of IAMStreamControl
  129.  
  130.     // Class adds default values suitable for immediate
  131.     // muting and unmuting of the stream.
  132.  
  133.     STDMETHODIMP StopAt( const REFERENCE_TIME * ptStop = NULL,
  134.              BOOL bSendExtra = FALSE,
  135.              DWORD dwCookie = 0 );
  136.     STDMETHODIMP StartAt( const REFERENCE_TIME * ptStart = NULL,
  137.                   DWORD dwCookie = 0 );
  138.     STDMETHODIMP GetInfo( AM_STREAM_INFO *pInfo);
  139.  
  140.     // Helper function for pin's receive method.  Call this with
  141.     // the sample and we'll tell you what to do with it.  We'll do a
  142.     // WaitForSingleObject within this call if one is required.  This is
  143.     // a "What should I do with this sample?" kind of call. We'll tell the
  144.     // caller to either flow it or discard it.
  145.     // If pSample is NULL we evaluate based on the current state
  146.     // settings
  147.     enum StreamControlState CheckStreamState( IMediaSample * pSample );
  148.  
  149. private:
  150.     // These don't require locking, but we are relying on the fact that
  151.     // m_StreamState can be retrieved with integrity, and is a snap shot that
  152.     // may have just been, or may be just about to be, changed.
  153.     HANDLE GetStreamEventHandle() const { return m_StreamEvent; }
  154.     enum StreamControlState GetStreamState() const { return m_StreamState; }
  155.     BOOL IsStreaming() const { return m_StreamState == STREAM_FLOWING; }
  156. };
  157.  
  158. #endif
  159.